﻿using KseCms.Application.Services;
using System.Security.Claims;

namespace KseCms.Application
{
    [Authorize]
    public class OrderAppService : IDynamicApiController
    {
        private readonly IOrderService _orderService;
        public OrderAppService(IOrderService orderService)
        {
            _orderService = orderService;
        }

        public async Task<PagedList<OrderDto>> GetPageList([FromQuery]PageDto page)
        {
            return await _orderService.GetList(page);
        }

        public async Task<OrderDto> Get(string id)
        {
            return await _orderService.GetById(id);
        }

        public async Task<object> Create(OrderDto order)
        {
            order.UserId = App.User?.FindFirstValue("UserId");

            await _orderService.Create(order);

            //To-Do delete ShoppingCart

            return Results.Ok();
        }

        public async Task<object> Delete(string id)
        {
            await _orderService.Delete(id);

            return Results.Ok();
        }

        public async Task<object> Update(OrderDto order)
        {
            await _orderService.Update(order);

            return Results.Ok();
        }
    }
}
